local iputils = require("resty.iputils")
local blacklist_ips = {
        "121.33.194.0/24",
        "172.81.214.240",
        "113.69.244.84",
        "212.64.71.75",
}

local headers = ngx.req.get_headers()
local client_ip = headers["X-FORWARDED-FOR"] or ngx.var.remote_addr or headers["X-REAL-IP"]

blacklist = iputils.parse_cidrs(blacklist_ips)
if iputils.ip_in_cidrs(client_ip , blacklist) then
        local msg = '{"code": 403, "message": "client_ip '.. client_ip ..' in blacklist"}'
        --ngx.header.content_type = "text/plain";
        ngx.header.content_type = "application/json";
        return ngx.print(msg)
        --return ngx.exit(ngx.HTTP_FORBIDDEN)
end


